package handler

import (
	"context"
	"log"
	"user_server/inter/dao"
	"user_server/inter/model"
	pb "user_server/proto"
)

type UserServer struct {
	pb.UnimplementedUserServer
}

// SayHello implements helloworld.GreeterServer
func (s *UserServer) Register(_ context.Context, in *pb.RegisterReq) (*pb.RegisterResp, error) {
	user := model.User{
		Tel:      in.Tel,
		Password: in.Password,
	}
	dao.Create(&user)
	return &pb.RegisterResp{
		Id: 1,
	}, nil
}
func (s *UserServer) Login(_ context.Context, in *pb.LoginReq) (*pb.LoginReqResp, error) {
	var user model.User
	dao.Find(in.Tel, in.Password, &user)
	if user.Id == 0 {
		log.Println("手机号或密码错误")
	}
	return &pb.LoginReqResp{
		Id: 1,
	}, nil
}
